import axios from 'axios'

export const InventoryService = class InventoryService {
    static inventoryService = null
    requestUrl = '/purchase/inventories'

    static getInstance() {
        if (this.inventoryService == null) {
            this.inventoryService = new InventoryService()
        }
        return this.inventoryService
    }

    /**
     * 分页查询库存
     * @param params
     * @returns {Promise<AxiosResponse<T>>}
     */
    getPage(params) {
        return axios.get(`${this.requestUrl}/page`, {
            params
        })
    }

    /**
     * 更新
     * @param data
     */
    update(data) {
        return axios.put(this.requestUrl, data)
    }

    /**
     * 调整库存预警
     * @param earlyWarning
     */
    updateEarlyWarning(earlyWarning) {
        return axios.get(`${this.requestUrl}/earlyWarning`,{
            params: {
                earlyWarning
            }
        })
    }
}
